package com.gangwangchina.android.contactlib.model;

import java.util.HashMap;
import java.util.Map;

import com.gangwangchina.android.contactlib.ContactsInterface;

import android.provider.ContactsContract.CommonDataKinds.Im;


public class IMAddress extends DataElement{
	public static final String IM = Im.DISPLAY_NAME;
	public static final String TYPE = Im.TYPE;
	public static final String CONTENT_ITEM_TYPE = Im.CONTENT_ITEM_TYPE;
	public static final String LABEL = Im.LABEL;
	public static final String DATA = Im.DATA;
		
	public static final String PROTOCOL = Im.PROTOCOL;
	public static final int PROTOCOL_AIM = Im.PROTOCOL_AIM;
	public static final int PROTOCOL_CUSTOM = Im.PROTOCOL_CUSTOM;
	public static final int PROTOCOL_GOOGLE_TALK = Im.PROTOCOL_GOOGLE_TALK;
	public static final int PROTOCOL_ICQ = Im.PROTOCOL_ICQ;
	public static final int PROTOCOL_JABBER = Im.PROTOCOL_JABBER;
	public static final int PROTOCOL_MSN = Im.PROTOCOL_MSN;
	public static final int PROTOCOL_NETMEETING = Im.PROTOCOL_NETMEETING;
	public static final int PROTOCOL_QQ = Im.PROTOCOL_QQ;
	public static final int PROTOCOL_SKYPE = Im.PROTOCOL_SKYPE;
	public static final int PROTOCOL_YAHOO = Im.PROTOCOL_YAHOO;
	


	public String im, label;;
	public int type;

	/**
	 * Creates a new IMAddress that is not (yet) present in the database
	 * @param im
	 * @return
	 */
	public static IMAddress newIMAddress(String im, int type){
		return new IMAddress(im, type);
	}

	/**
	 * Creates an object representation of a IMAddress that is present in the database
	 * @param pcId
	 * @param im
	 * @return
	 */
	public static IMAddress recoverIMAddress(long pcId, String im, int type){
		return new IMAddress(pcId, im, type);
	}

	/**
	 * Creates a new IMAddress
	 * @param pcId the PersonContact the Notes is linked to
	 * @param im
	 */
	private IMAddress(long pcId, String im, int type){
		this(pcId);
		this.im = im;
		this.type = type;
		//this.label = label;
	}

	private IMAddress(String im, int type){
		this(ContactsInterface.NO_ID, im, type);
	}

	private IMAddress(long pcId){
		super(pcId, CONTENT_ITEM_TYPE);
	}



//	@Override
	public String toString(){		
//		return "{'value':" + this.safeJson(im) + "type" + this.safeJson(type) + "}";	
		return "";
	}

	@Override
	public Map<String, Object> getDataColumns() {
		Map<String, Object> datas = new HashMap<String, Object>();
		datas.put(DATA, im);
		datas.put(PROTOCOL, type);
		return datas;
	}

	@Override
	public boolean setProperty(String key, Object value){
		if(key.equals(IM)) im = (String) value;
		if(key.equals(TYPE)) type = Integer.valueOf((String) value);
		// if(key.equals(LABEL)) label = value;
		else return super.setProperty(key, value);
		return true;
	}

	@Override
	public Object getProperty(String key){
		if(key.equals(IM)) return im;
		if(key.equals(TYPE)) return String.valueOf(type);
		// if(key.equals(LABEL)) return label;
		return super.getProperty(key);
	}
}
